
   //创建支付安卓手机,苹果手机发送申请(授权头像昵称)
   function creatMyCardPay (e) {
    let that = this;
    let isAccredit = that.data.isAccredit;
    if (e.detail.iv) {
      if (!isAccredit) {//弹出授权框且同意
        utils.AuthorizeUserInfoOld(e, that.data.loginCode);
      }
      that.toCreatMyCardPay();
    } else {
      wx.showToast({
        title: '请授权微信头像、昵称',
        mask: true
      })
    }
  }

  //创建支付安卓手机,苹果手机发送申请(先授权微信头像昵称)===用户授权api修改
  function creatMyCardPayByfile () {
    let that = this;
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log('用于完善会员资料', res);
        utils.AuthorizeUserInfo(res, '', function (flag) {
          if (flag) {
            that.toCreatMyCardPay();
          } else {//注册失败，重新点击授权
            wx.login({
              success: function (res) {
                that.data.loginCode = res.code;
              }
            })
          }
        });
      },
      fail: (err) => {
        wx.showToast({
          title: '请授权微信头像、昵称',
          mask: true
        })
      }
    })
  }

  //创建支付安卓手机,苹果手机发送申请
  function toCreatMyCardPay (e) {
    var that = this;
    var cardInfo = that.data.cardInfo.CardInfo;
    if (that.data.versionid == 3) {
      that.createStaffPayRequest(that.data.versionid);
    } else {
      if (app.globalData.platform != 'ios' || that.data.versionid == 1) {
        wxpay.createStaffOrder(app, cardInfo.Id, that.data.versionid);
        utils.aiCardActionRecord(24);
      } else {
        //发送创建申请
        that.createStaffPayRequest(that.data.versionid);
      }
    }
  }

  //申请代付
  function applyCardPay (e) {
    var that = this;
    let isAccredit = that.data.isAccredit;
    if (e.detail.iv) {
      if (!isAccredit) {//弹出授权框且同意
        utils.AuthorizeUserInfoOld(e, that.data.loginCode);
      }
      that.createStaffPayRequest(that.data.versionid);
    } else {
      wx.showToast({
        title: '请授权微信头像、昵称',
        mask: true
      })
    }
  }

  //申请代付===用户授权api修改
  function applyCardPayByfile () {
    var that = this;
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log('用于完善会员资料', res);
        utils.AuthorizeUserInfo(res, '', function (flag) {
          if (flag) {
            that.createStaffPayRequest(that.data.versionid);
          }
        });
      },
      fail: (err) => {
        wx.showToast({
          title: '请授权微信头像、昵称',
          mask: true
        })
      }
    })
  }

  //申请代付
  function createStaffPayRequest (versionid) {
    let that = this;
    var cardInfo = that.data.cardInfo.CardInfo;
    wx.showLoading({
      title: '申请中',
      mask: true
    })
    wx.request({
      url: app.globalData.host + '/api/Staff/CreateStaffPayRequest?fromUid=' + app.globalData.userInfo.Uid + '&toUid=' + cardInfo.Uid + '&industryCode=' + versionid,
      success: function (res) {
        wx.hideLoading();
        if (res.data.Code == 0) {
          wx.showToast({
            title: '申请成功!'
          })
          that.dialogsState();
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  }

  module.exports = {
    creatMyCardPay: creatMyCardPay,
    toCreatMyCardPay: toCreatMyCardPay,
    applyCardPay: applyCardPay,
    applyCardPayByfile: applyCardPayByfile,
    createStaffPayRequest: createStaffPayRequest
  }